package org.ruoyi.dhuman.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.ruoyi.common.core.domain.R;
import org.ruoyi.common.core.validate.AddGroup;
import org.ruoyi.common.core.validate.EditGroup;
import org.ruoyi.common.idempotent.annotation.RepeatSubmit;
import org.ruoyi.common.log.annotation.Log;
import org.ruoyi.common.log.enums.BusinessType;
import org.ruoyi.common.web.core.BaseController;
import org.ruoyi.core.page.PageQuery;
import org.ruoyi.core.page.TableDataInfo;
import org.ruoyi.dhuman.domain.bo.DhumanPptBo;
import org.ruoyi.dhuman.domain.vo.DhumanPptVo;
import org.ruoyi.dhuman.service.IDhumanPptService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 数字人讲PPT
 *
 * @author wangliang
 * @date Tue Oct 14 12:06:13 CST 2025
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/api/dhumanPPT")
public class DhumanPptController extends BaseController {

    private final IDhumanPptService dhumanPptService;

	/**
	 * 查询数字人讲PPT列表
	 */
	@SaCheckPermission("dhuman:dhumanPpt:list")
	@GetMapping("/list")
    public R<TableDataInfo<DhumanPptVo>> list(DhumanPptBo bo, PageQuery pageQuery) {
		TableDataInfo<DhumanPptVo> result = dhumanPptService.queryPageList(bo, pageQuery);
		return R.ok(result);
    }

    /**
     * 导出数字人讲PPT列表
     */
//    @SaCheckPermission("dhuman:dhumanPpt:export")
//    @Log(title = "数字人讲PPT", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(DhumanPptBo bo, HttpServletResponse response) {
//        List<DhumanPptVo> list = dhumanPptService.queryList(bo);
//        ExcelUtil.exportExcel(list, "数字人讲PPT", DhumanPptVo.class, response);
//    }

    /**
     * 获取数字人讲PPT详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("dhuman:dhumanPpt:query")
    @GetMapping("/{id}")
    public R<DhumanPptVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(dhumanPptService.queryById(id));
    }

    /**
     * 新增数字人讲PPT
     */
    @SaCheckPermission("dhuman:dhumanPpt:add")
    @Log(title = "数字人讲PPT", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody DhumanPptBo bo) {
        return toAjax(dhumanPptService.insertByBo(bo));
    }

    /**
     * 修改数字人讲PPT
     */
    @SaCheckPermission("dhuman:dhumanPpt:edit")
    @Log(title = "数字人讲PPT", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody DhumanPptBo bo) {
        return toAjax(dhumanPptService.updateByBo(bo));
    }

    /**
     * 删除数字人讲PPT
     *
     * @param ids 主键串
     */
    @SaCheckPermission("dhuman:dhumanPpt:remove")
    @Log(title = "数字人讲PPT", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(dhumanPptService.deleteWithValidByIds(List.of(ids), true));
    }
}
